home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / cd.test < prev    next >
Text File  |  1992-11-06  |  3KB  |  107 lines

  1. # Commands covered:  cd, pwd
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /user6/ouster/tcl/tests/RCS/cd.test,v 1.17 91/12/06 11:49:02 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. catch {exec rm -rf cd.dir}
  21. exec mkdir cd.dir
  22. exec cat << "Sample text" > cd.dir/test.file
  23. set cwd [exec pwd]
  24.  
  25. test cd-1.1 {simple pwd check} {
  26.     pwd
  27. } $cwd
  28.  
  29. cd cd.dir
  30. test cd-2.1 {changing directories} {
  31.     list [exec pwd]
  32. } $cwd/cd.dir
  33. test cd-2.2 {changing directories} {
  34.     pwd
  35. } $cwd/cd.dir
  36. test cd-2.3 {changing directories} {
  37.     exec cat test.file
  38. } "Sample text"
  39. cd ..
  40. test cd-2.4 {changing directories} {
  41.     exec pwd 
  42. } $cwd
  43. test cd-2.5 {changing directories} {
  44.     pwd 
  45. } $cwd
  46. test cd-2.6 {changing directories} {
  47.     exec cat cd.dir/test.file
  48. } "Sample text"
  49.  
  50. # The tests below seem to fail on lots of machines for a variety
  51. # of reasons, such as the auto-mounter, home directories that are
  52. # symbolic links, etc.
  53.  
  54. if $atBerkeley {
  55.     set home [exec sh -c "cd; pwd"]
  56.     test cd-2.7 {changing directories} {
  57.     cd ~
  58.     set x [list [exec pwd] [pwd]]
  59.     cd $cwd
  60.     set x
  61.     } "$home $home"
  62.     test cd-2.8 {changing directories} {
  63.     cd
  64.     set x [list [exec pwd] [pwd]]
  65.     cd $cwd
  66.     set x
  67.     } "$home $home"
  68. }
  69.  
  70. test cd-3.1 {cd return value} {
  71.     cd .
  72. } {}
  73.  
  74. test cd-4.1 {errors in cd command} {
  75.     list [catch {cd 1 2} msg] $msg $errorCode
  76. } {1 {wrong # args: should be "cd dirName"} NONE}
  77. test cd-4.2 {errors in cd command} {
  78.     string tolower [list [catch {cd _bad_dir} msg] $msg $errorCode]
  79. } {1 {couldn't change working directory to "_bad_dir": no such file or directory} {unix enoent {no such file or directory}}}
  80. test cd-4.3 {errors in cd command} {
  81.     string tolower [list [catch {cd cd.dir/test.file} msg] $msg $errorCode]
  82. } {1 {couldn't change working directory to "cd.dir/test.file": not a directory} {unix enotdir {not a directory}}}
  83. test cd-4.4 {errors in cd command} {
  84.     set home $env(HOME)
  85.     unset env(HOME)
  86.     set x [list [catch cd msg] $msg]
  87.     set env(HOME) $home
  88.     set x
  89. } {1 {couldn't find HOME environment variable to expand "~"}}
  90.  
  91. test cd-5.1 {errors in pwd command} {
  92.     list [catch {pwd a} msg] $msg
  93. } {1 {wrong # args: should be "pwd"}}
  94. exec mkdir cd.dir/child
  95. cd cd.dir/child
  96. exec chmod 111 ..
  97. if {$user != "root"} {
  98.     test cd-5.2 {errors in pwd command} {
  99.     catch pwd msg
  100.     } 1
  101. }
  102. cd $cwd
  103. exec chmod 775 cd.dir
  104.  
  105. catch {exec rm -rf cd.dir}
  106. format ""
  107.